// 嵌入类型用于接口
package main

import "fmt"

type notifier interface {
	notify()
}

type user struct {
	name  string
	email string
}

func (u *user) notify() {
	fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
}

type admin struct {
	user
	level string
}

//通过admin类型值的指针
func (a *admin) notify() {
	fmt.Printf("Sending admin email to %s<%s>\n", a.name, a.email)
}

func main() {
	//创建一个用户
	ad := admin{ //外部类型
		user: user{ //内部类型
			name:  "john smith",
			email: "john@yahoo.com",
		},
		level: "super",
	}

	// 给admin用户发送一个通知
	//用于实现接口的内部类型的方法，被提升到外部类型
	sendNotification(&ad) //Sending admin email to john smith<john@yahoo.com>

	ad.user.notify() //Sending user email to john smith<john@yahoo.com>
	ad.notify()      //Sending admin email to john smith<john@yahoo.com>
}

func sendNotification(n notifier) {
	n.notify()
}
